package top.zhangjianyong.tools.controller;

import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.zhangjianyong.tools.annotation.RequestMessageType;
import top.zhangjianyong.tools.constant.MessageType;
import top.zhangjianyong.tools.parm.wechat.WechatRequestMessage;
import top.zhangjianyong.tools.service.api.WechatService;
import top.zhangjianyong.tools.user.VerifyUser;

import java.util.Map;

/**
 * @author zhangjianyong
 * @since 2025/3/18 下午12:34
 */
@VerifyUser(login = false)
@Slf4j
@RestController
@RequestMapping("/wechat")
@RequestMessageType(MessageType.XML)
public class WechatController {

    @Autowired
    private WechatService wechatService;

    @GetMapping(value = "/revice")
    public Long revice(@RequestParam Map<String, String> params) {
        log.info("get微信消息：{}", params);
        return wechatService.revice(params);
    }

    @PostMapping(value = "/revice")
    public String reviceMessage(@RequestParam Map<String, String> params,
                                @RequestBody WechatRequestMessage message) {
        log.info("post微信消息：{}", params);
        log.info("post微信消息：{}", JSONObject.toJSONString(message));
        return wechatService.reviceMessage(params, message);
    }


}
